package alvin.hwang.tinygrid;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TinyGridServlet extends HttpServlet {

	private static final long serialVersionUID = 5136753380930108054L;

	public TinyGridServlet() {
		super();
	}

	public void destroy() {
		super.destroy(); 
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		int page = Integer.valueOf(request.getParameter("page"));
		int resultsPerPage = Integer.valueOf(request.getParameter("rp"));
		String sortOrder = request.getParameter("sortorder");
		String sortName = request.getParameter("sortname");
		
		System.out.println("====================from tinygrid =======================");
		System.out.println("page : " + page);
		System.out.println("rp : " + resultsPerPage);
		System.out.println("sortorder : " + sortOrder);
		System.out.println("sortname : " + sortName);
		System.out.println("====================from tinygrid =======================");
		
		response.setContentType("text/xml; charset=GBK");
		PrintWriter out = response.getWriter();
		out.write(DataGenerator.generateXml(page, resultsPerPage));
		out.flush();
		out.close();
	}

	public void init() throws ServletException {
		
	}

}
